package learningThread.syn.synchronizedMethodLockObj.lock.queueLength;


/**
 *  lock.getQueueLength 可以知道多少等待线程
 *
 *  lock.getQueueLength(Condition condition)可知指定的 condition 等待的线程是多少
 */
public class TestQueueLength {

    public static void main(String[] args) {
        try {
            Service service = new Service();
            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    service.serviceMethod();
                }
            };
            Thread[] threads = new Thread[10];
            for (int i = 0; i < 10; i++) {
                threads[i] = new Thread(runnable);
            }
            for (int i = 0; i < threads.length; i++) {
                threads[i].start();
            }
            Thread.sleep(2000);
            System.out.println("有线程数:"+service.lock.getQueueLength()+"在等待获取锁");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
